#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <gtk/gtk.h>

#include "fonction.h"
#include "donnees.h"
#include "constantes.h"
#include "graphique.h"
#include <glib.h>

static pToolbar = NULL;

int main(int argc, char **argv)
{
	GtkWidget *pWindow;
    GtkWidget * vbox1;
	GtkWidget * pButton;
    GtkWidget *pMenuBar;
    GtkWidget *pMenu;
    GtkWidget *pMenuItem;

	/* pour creer un tableau de binomes (tableau de structure)*/
	gtk_init(&argc, &argv);

	/* Creation de la fenetre principale */
	pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_maximize(GTK_WINDOW(pWindow));
	gtk_window_set_title(GTK_WINDOW(pWindow), "Super Trombi ");
	g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL);

	vbox1=gtk_vbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(pWindow),vbox1);

	/**** Creation du menu ****/

    /* ETAPE 1 */
    pMenuBar = gtk_menu_bar_new();
    /** Premier sous-menu **/
    /* ETAPE 2 */
    pMenu = gtk_menu_new();
    /* ETAPE 3 */

    pMenuItem = gtk_menu_item_new_with_label("Ouvrir");
    g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(saisie), (GtkWidget*) pWindow);
    gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);

    pMenuItem = gtk_menu_item_new_with_label("Fermer");
    g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(Fermer), (GtkWidget*) pWindow);
    gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);

    pMenuItem = gtk_menu_item_new_with_label("Quitter");
    g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(OnQuitter), (GtkWidget*) pWindow);
    gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);
    /* ETAPE 4 */
    pMenuItem = gtk_menu_item_new_with_label("Fichier");
    /* ETAPE 5 */
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu);
    /* ETAPE 6 */
    gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem);

    /** Second sous-menu **/
    /* ETAPE 2 */
    pMenu = gtk_menu_new();
    /* ETAPE 3 */
    pMenuItem = gtk_menu_item_new_with_label("A propos de...");
    g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(OnAbout), (GtkWidget*) pWindow);
    gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);
    /* ETAPE 4 */
    pMenuItem = gtk_menu_item_new_with_label("?");
    /* ETAPE 5 */
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu);
    /* ETAPE 6 */
    gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem);

	/*creation des boutons */
	pButton=gtk_button_new_with_label(g_locale_to_utf8( "Selectionnez un fichier CSV", -1, NULL, NULL, NULL));

	/* Ajout des elements */
	pToolbar = gtk_toolbar_new();

	gtk_toolbar_append_item (GTK_TOOLBAR(pToolbar), "Promo",    "Promo", NULL, NULL, G_CALLBACK(promo2), NULL);
	gtk_toolbar_append_item (GTK_TOOLBAR(pToolbar), "STPI",     "STPI", NULL, NULL, G_CALLBACK(stpi_fonction), NULL);
	gtk_toolbar_append_item (GTK_TOOLBAR(pToolbar), "EXTERNES", "EXTERNES", NULL, NULL, G_CALLBACK(externe_fonction), NULL);
	gtk_toolbar_append_item (GTK_TOOLBAR(pToolbar), "Groupe A", "Groupe A", NULL, NULL, G_CALLBACK(groupeA), NULL);
	gtk_toolbar_append_item (GTK_TOOLBAR(pToolbar), "Groupe B", "Groupe B", NULL, NULL, G_CALLBACK(groupeB), NULL);
	gtk_toolbar_append_item (GTK_TOOLBAR(pToolbar), "Binomes Groupe A", "Binomes Groupe A", NULL, NULL, G_CALLBACK(binomeA), NULL);
	gtk_toolbar_append_item (GTK_TOOLBAR(pToolbar), "Binomes Groupe B", "Binomes Groupe B", NULL, NULL, G_CALLBACK(binomeB), NULL);
	gtk_toolbar_append_item (GTK_TOOLBAR(pToolbar), "Afficher Trombi Photo", "Afficher Trombi Photo", NULL, NULL, G_CALLBACK(trombiphoto), NULL);

    /* on insere le menu */
    gtk_box_pack_start(GTK_BOX(vbox1), pMenuBar, FALSE, FALSE, 0);

    afficherTableau1(vbox1);

	/*ajout du bouton dans la vbox1 */
	gtk_box_pack_start(GTK_BOX(vbox1),pButton,FALSE,FALSE,0);

	gtk_box_pack_start(GTK_BOX(vbox1),pToolbar,FALSE,FALSE,0);
	/* ajout du boutton afficher */

	afficherTableau2(vbox1);

	/* fonction du bouton */
	g_signal_connect(G_OBJECT(pButton), "clicked", G_CALLBACK(saisie), NULL);

	/* on ajoute le tout dans la fenetre */
	gtk_widget_show_all(pWindow);
	gtk_main();

	return EXIT_SUCCESS;
}
